package com.web.cms.doc.dao;

import com.blue.jdbc.BaseDao;
import com.web.cms.doc.model.DocContent;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("cmsDocContentDao")
public class DocContentDao extends BaseDao<DocContent>
{
	public DocContentDao()
	{
	}

	public void save(Integer id, String content)
	{
		DocContent docContent = new DocContent();
		docContent.setId(id);
		docContent.setContent(content);
		
		String sql = "select id from cms_doc_content where id=?";
		List<Integer> idList = jdbcTemplate.queryForList(sql, Integer.class, id);
		if (idList == null || idList.isEmpty()) // 插入
		{
			this.save(docContent);
		}
		else // 更新
		{
			if (content == null || content.isEmpty())
				return;
			
			this.update(docContent);
		}
	}
	
	public String getContent(Integer id)
	{
		String sql = "select content from cms_doc_content where id=?";
		List<String> list = jdbcTemplate.queryForList(sql, String.class, id);
		if (list == null || list.isEmpty())
			return null;
		
		return list.get(0);
	}
	
}
